using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AssetFrame.Message;
using System.Reflection;
using System.Data;
using MySql.Data.MySqlClient;
using SysFrame.BP;
using SysFrame.Message;

namespace AssetFrame.BP
{
    /// <summary>
    /// asset_a3方法
    /// </summary>
    public class MySQLasset_a3: Iasset_a3
    {

        /// <summary>
        /// 得到asset_a3实体
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public List<Msasset_a3> Getasset_a3MsByQuery(MsQuery msq)
        {
            List<Msasset_a3> listms=new List<Msasset_a3>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            sb.Append("select asset_a3.* ");
            sb.Append(" from asset_a3 ");
            sb.Append(" where 1=1 ").Append(msq.strquery);
            if(msq.strorder != null && msq.strorder != "")
            {
				sb.Append(" order by ").Append(msq.strorder);
            }
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                DataSet ds = DbHelperMySQL.Query(lstCmdText[0].ToString());
               if (ds != null && ds.Tables.Count != 0 && ds.Tables[0].Rows.Count != 0)
                {
                	foreach(DataRow dr in ds.Tables[0].Rows)
                	{
                    	Msasset_a3 ms = new Msasset_a3();
                    	if(dr["ASSET_A3_AUTOID"].ToString()!=""){ms.ASSET_A3_AUTOID=int.Parse(dr["ASSET_A3_AUTOID"].ToString());}
                    	if(dr["ASSET_A3_ISDEL"]!=null){ms.ASSET_A3_ISDEL=dr["ASSET_A3_ISDEL"].ToString();}
                    	if(dr["ASSET_A3_MAKETIME"]!=null){ms.ASSET_A3_MAKETIME=dr["ASSET_A3_MAKETIME"].ToString();}
                    	if(dr["ASSET_A3_MAKEUSER"]!=null){ms.ASSET_A3_MAKEUSER=dr["ASSET_A3_MAKEUSER"].ToString();}
                    	if(dr["ASSET_A3_PARENTID"]!=null){ms.ASSET_A3_PARENTID=dr["ASSET_A3_PARENTID"].ToString();}
                    	if(dr["ASSET_A3_MAKEFROM"]!=null){ms.ASSET_A3_MAKEFROM=dr["ASSET_A3_MAKEFROM"].ToString();}
                    	if(dr["ASSET_A3_10"]!=null){ms.ASSET_A3_10=dr["ASSET_A3_10"].ToString();}
                    	if(dr["ASSET_A3_20"]!=null){ms.ASSET_A3_20=dr["ASSET_A3_20"].ToString();}
                    	if(dr["ASSET_A3_30"]!=null){ms.ASSET_A3_30=dr["ASSET_A3_30"].ToString();}
                    	if(dr["ASSET_A3_40"]!=null){ms.ASSET_A3_40=dr["ASSET_A3_40"].ToString();}
                    	if(dr["ASSET_A3_50"]!=null){ms.ASSET_A3_50=dr["ASSET_A3_50"].ToString();}
                    	if(dr["ASSET_A3_60"]!=null){ms.ASSET_A3_60=dr["ASSET_A3_60"].ToString();}
                    	if(dr["ASSET_A3_70"]!=null){ms.ASSET_A3_70=dr["ASSET_A3_70"].ToString();}
                    	listms.Add(ms);
                	}
                }
            }
            catch{}
            return listms;
        }

        /// <summary>
        ///  保存asset_a3信息
        /// </summary>
        /// <param name="ms">实体信息 通过ASSET_A3_AUTOID进行判断有ASSET_A3_AUTOID就是update</param>
        /// <returns>消息</returns>
        public MsReturned Saveasset_a3(Msasset_a3 ms)
        {
            MsReturned msr = new MsReturned();
            if(ms.ASSET_A3_AUTOID !=null && ms.ASSET_A3_AUTOID.ToString() !="" && ms.ASSET_A3_AUTOID.ToString() != "0")
            {
            	msr = Upasset_a3(ms);
            }
            else
            {
            	msr = Addasset_a3(ms);
            }
            return msr;
        }

        /// <summary>
        ///  新增asset_a3信息
        /// </summary>
        /// <param name="ms">实体信息 通过ASSET_A3_AUTOID进行判断有ASSET_A3_AUTOID就是update</param>
        /// <returns>消息</returns>
        public MsReturned Addasset_a3(Msasset_a3 ms)
        {
            List<string> lstResult = new List<string>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            MsReturned msr = new MsReturned();
            int newRateId = DataBase.GetMaxId("asset_a3", "ASSET_A3_AUTOID");
            sb.Append("insert into asset_a3 (");
            sb.Append("ASSET_A3_AUTOID,ASSET_A3_ISDEL,ASSET_A3_MAKETIME,ASSET_A3_MAKEUSER,ASSET_A3_PARENTID,");
            sb.Append("ASSET_A3_MAKEFROM,ASSET_A3_10,ASSET_A3_20,ASSET_A3_30,ASSET_A3_40,");
            sb.Append("ASSET_A3_50,ASSET_A3_60,ASSET_A3_70");
            sb.Append(")");
            sb.Append("values ( ");
            sb.Append(newRateId.ToString()).Append(",");
            sb.Append("@ASSET_A3_ISDEL,@ASSET_A3_MAKETIME,@ASSET_A3_MAKEUSER,@ASSET_A3_PARENTID,");
            sb.Append("@ASSET_A3_MAKEFROM,@ASSET_A3_10,@ASSET_A3_20,@ASSET_A3_30,@ASSET_A3_40,");
            sb.Append("@ASSET_A3_50,@ASSET_A3_60,@ASSET_A3_70)");
            MySqlParameter[] parameters = {
            		new MySqlParameter("@ASSET_A3_AUTOID", MySqlDbType.Int32,11),
            		new MySqlParameter("@ASSET_A3_ISDEL", MySqlDbType.VarChar,1),
            		new MySqlParameter("@ASSET_A3_MAKETIME", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A3_MAKEUSER", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A3_PARENTID", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A3_MAKEFROM", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A3_10", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A3_20", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A3_30", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A3_40", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A3_50", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A3_60", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A3_70", MySqlDbType.VarChar,100)};
            parameters[0].Value = ms.ASSET_A3_AUTOID;
            parameters[1].Value = ms.ASSET_A3_ISDEL;
            parameters[2].Value = ms.ASSET_A3_MAKETIME;
            parameters[3].Value = ms.ASSET_A3_MAKEUSER;
            parameters[4].Value = ms.ASSET_A3_PARENTID;
            parameters[5].Value = ms.ASSET_A3_MAKEFROM;
            parameters[6].Value = ms.ASSET_A3_10;
            parameters[7].Value = ms.ASSET_A3_20;
            parameters[8].Value = ms.ASSET_A3_30;
            parameters[9].Value = ms.ASSET_A3_40;
            parameters[10].Value = ms.ASSET_A3_50;
            parameters[11].Value = ms.ASSET_A3_60;
            parameters[12].Value = ms.ASSET_A3_70;
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(lstCmdText[0].ToString(),parameters);
                if (iexe > 0)
                {
                    msr.strMsId = newRateId.ToString();
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            lstCmdText = null;
            sb = null;
            return msr;
        }

        /// <summary>
        ///  更新asset_a3信息
        /// </summary>
        /// <param name="ms">实体信息 通过ASSET_A3_AUTOID进行判断有ASSET_A3_AUTOID就是update</param>
        /// <returns>消息</returns>
        public MsReturned Upasset_a3(Msasset_a3 ms)
        {
            List<string> lstResult = new List<string>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            MsReturned msr = new MsReturned();
           	sb.Append("update asset_a3 set ");
           	sb.Append(" ASSET_A3_AUTOID='").Append(ms.ASSET_A3_AUTOID).Append("' ");// ASSET_A3_AUTOID AutoID
           	if (ms.ASSET_A3_ISDEL !=null && ms.ASSET_A3_ISDEL.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A3_ISDEL='").Append(ms.ASSET_A3_ISDEL).Append("' ");// ASSET_A3_ISDEL 是否删除
           	}
           	if (ms.ASSET_A3_MAKETIME !=null && ms.ASSET_A3_MAKETIME.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A3_MAKETIME='").Append(ms.ASSET_A3_MAKETIME).Append("' ");// ASSET_A3_MAKETIME 新增时间
           	}
           	if (ms.ASSET_A3_MAKEUSER !=null && ms.ASSET_A3_MAKEUSER.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A3_MAKEUSER='").Append(ms.ASSET_A3_MAKEUSER).Append("' ");// ASSET_A3_MAKEUSER 新增人
           	}
           	if (ms.ASSET_A3_PARENTID !=null && ms.ASSET_A3_PARENTID.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A3_PARENTID='").Append(ms.ASSET_A3_PARENTID).Append("' ");// ASSET_A3_PARENTID 上级ID
           	}
           	if (ms.ASSET_A3_MAKEFROM !=null && ms.ASSET_A3_MAKEFROM.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A3_MAKEFROM='").Append(ms.ASSET_A3_MAKEFROM).Append("' ");// ASSET_A3_MAKEFROM 来源
           	}
           	if (ms.ASSET_A3_10 !=null && ms.ASSET_A3_10.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A3_10='").Append(ms.ASSET_A3_10).Append("' ");// ASSET_A3_10 品牌名称
           	}
           	if (ms.ASSET_A3_20 !=null && ms.ASSET_A3_20.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A3_20='").Append(ms.ASSET_A3_20).Append("' ");// ASSET_A3_20 品牌编号
           	}
           	if (ms.ASSET_A3_30 !=null && ms.ASSET_A3_30.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A3_30='").Append(ms.ASSET_A3_30).Append("' ");// ASSET_A3_30 
           	}
           	if (ms.ASSET_A3_40 !=null && ms.ASSET_A3_40.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A3_40='").Append(ms.ASSET_A3_40).Append("' ");// ASSET_A3_40 
           	}
           	if (ms.ASSET_A3_50 !=null && ms.ASSET_A3_50.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A3_50='").Append(ms.ASSET_A3_50).Append("' ");// ASSET_A3_50 
           	}
           	if (ms.ASSET_A3_60 !=null && ms.ASSET_A3_60.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A3_60='").Append(ms.ASSET_A3_60).Append("' ");// ASSET_A3_60 
           	}
           	if (ms.ASSET_A3_70 !=null && ms.ASSET_A3_70.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A3_70='").Append(ms.ASSET_A3_70).Append("' ");// ASSET_A3_70 
           	}
           	sb.Append(" where ASSET_A3_AUTOID='").Append(ms.ASSET_A3_AUTOID).Append("'");// ASSET_A3_AUTOID AutoID
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(lstCmdText[0].ToString());
                if (iexe > 0)
                {
                    msr.strMsId = ms.ASSET_A3_AUTOID.ToString();
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            lstCmdText = null;
            sb = null;
            return msr;
        }

        /// <summary>
        /// 得到数据类型
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns>数据类型</returns>
        public MsReturned Getasset_a3ByQuery(MsQuery msq)
        {
        	DataSet ds = null;
        	MsReturned msr = new MsReturned();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            sb.Append("select asset_a3.* ");
            sb.Append(" from asset_a3 ");
            sb.Append(" where 1=1 ").Append(msq.strquery);
            if(msq.strorder!=null && msq.strorder != "")
            {
				sb.Append(" order by ").Append(msq.strorder);
            }
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                ds = DbHelperMySQL.Query(lstCmdText[0].ToString());
            }
            catch{}
            msr.data = ds;
            return msr;
        }

        /// <summary>
        /// 删除asset_a3
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public MsReturned Deleteasset_a3ByQuery(MsQuery msq)
        {
            StringBuilder sb = new StringBuilder();
            MsReturned msr = new MsReturned();
            sb.Append(" delete from asset_a3 where ASSET_A3_AUTOID > 0 ").Append(msq.strquery);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(sb.ToString());
                if (iexe > 0)
                {
                    msr.strMsId = "1";
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            sb = null;
            return msr;
        }

    }
}
